<template>
  <div class="min-container">
    <client-title id="server_m" title="性能强大、安全稳定的多云产品" />
    <div class="content-container">
      <div class="category-row">
        <div
          class="category-item"
          :class="{ actvie: item.value == activeCategory }"
          v-for="(item, index) in categoryList"
          :key="index"
          @click="handleCategory(item)"
        >
          {{ item.label || "无" }}
        </div>
      </div>
      <div class="list">
        <el-row>
          <el-col :span="8" class="left-sapn" @click="handleToGov"> </el-col>
          <!-- 中酒云&阿里云 -->
          <el-col :span="16" class="list-row" v-if="activeCategory === '1'">
            <div v-for="(item, index) in dataList" :key="index" class="item">
              <div class="name">{{ item.serverName }}</div>
              <div class="into">{{ item.remark }}</div>
              <div class="btn-content">
                <div class="btn-name">{{ item.serverType }}</div>
              </div>
              <div class="price">
                ¥ {{ item.price || 0 }}元<span> /{{ getMode(item.billingMode) }}</span>
              </div>
              <div class="btn" @click="handleBuyGov(item)">立即购买</div>
            </div>
          </el-col>
          <!-- 华为云 -->
          <el-col :span="16" class="list-row" v-else>
            <div
              class="item item-huaweiyun"
              v-for="(item, index) in huaweiyunDataList"
              :key="index"
            >
              <h3 class="service-title">{{ item.name }}</h3>
              <p>{{ item.description }}</p>
              <div class="tag-box">
                <el-tag
                  v-for="(tag, index) in item.label"
                  :key="index"
                  class="ml-2 tag-one"
                  type="info"
                  >{{ tag }}</el-tag
                >
              </div>
              <div class="service-msg-box">
                <span>规格</span>
                <span class="detailed-information">{{ item.specifications }}</span>
              </div>
              <div class="service-msg-box">
                <span>固定带宽</span>
                <span class="detailed-information">{{ item.bandwidth }}</span>
              </div>
              <div class="service-msg-box">
                <span>数据中心</span>
                <span class="detailed-information">{{ item.dataCenter }}</span>
              </div>
              <div class="service-msg-box">
                <span>时长</span>
                <span class="detailed-information">{{ item.duration }}</span>
              </div>
              <span class="price-box preferential-price">￥{{ item.price }}</span>
              <el-button class="go-buy" @click="goBuyGov(item)">立即购买</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <client-title id="market_m" title="丰富、优质的云服务和应用" class="content-title" />
    <div class="content-container">
      <div class="list">
        <el-row>
          <el-col :span="8" class="left-sapn purple" @click="handleToMarket"> </el-col>
          <el-col :span="16" class="list-row">
            <div v-for="(item, index) in marketLists" :key="index" class="item">
              <div class="name">{{ item.title }}</div>
              <div class="into">{{ item.intro }}</div>
              <div class="btn-content">
                <div class="btn-name">{{ item.corporateName }}</div>
              </div>
              <div class="price">¥ {{ item.lowestPrice || 0 }}元</div>
              <div class="btn" @click="handleToMarketDetail(item)">立即购买</div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <Buy-modal
      v-model:show="buyShow"
      :product="productInfo"
      shoppingCarEnums="GOV_CLOUD"
    />
  </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from "vue";
import ClientTitle from "@/components/client-title/client-title.vue";
import { marketList } from "@/api/other";
import { govList, huaweicloudList } from "@/api/zhengWuYun";
import { useRouter } from "vue-router";
const router = useRouter();

const categoryList = ref<any>([
  { label: "中酒云", value: "1" },
  { label: "华为云", value: "2" },
]); // 类目列表
const activeCategory = ref("1"); // 选中类目
const dataList = ref<any>([]); // 主机列表
const huaweiyunDataList = ref<any>([]); // 华为云主机列表
const marketLists = ref<any>([]); // 云市场列表
const buyShow = ref(false); // 购买弹窗
const productInfo = ref<any>({}); // 产品信息
const modeList = ref<any>([
  { label: "次", value: 0 },
  { label: "天", value: 1 },
  { label: "月", value: 30 },
  { label: "年", value: 365 },
]);

onMounted(() => {
  getGovList();
  getMarketList();
});

// 获取华为云列表
const getHuaweicloudList = () => {
  huaweicloudList().then((res: any) => {
    let list = res.data.map((i: any) => {
      return {
        ...i,
        label: i.label ? i.label.split(",") : [],
      };
    });
    huaweiyunDataList.value = list;
  });
};

// 选择类目
const handleCategory = (row: any) => {
  activeCategory.value = row.value;
  if (row.value == "1") {
    getGovList();
  } else {
    getHuaweicloudList();
  }
};

// 获取政务云列表
const getGovList = () => {
  let data = {
    params: {
      pageNum: 1,
      pageSize: 6,
    },
  };
  govList(data).then((res: any) => {
    dataList.value = res.rows;
  });
};

// 获取计费方式
const getMode = (val: any) => {
  let row = modeList.value.find((item: any) => item.value == val);
  return row ? row.label : "";
};

// 获取市场列表
const getMarketList = () => {
  let data = {
    searchValue: "",
    params: {
      sort: "desc",
      sortField: "price",
      pageNum: 1,
      pageSize: 6,
    },
  };
  marketList(data).then((res: any) => {
    let list = res.rows;
    list.forEach((i: any) => {
      i.intro = i.intro ? i.intro.replace(/<[^>]*>/g, "") : "";
    });
    marketLists.value = list;
  });
};

// 购买政务云
const handleBuyGov = (item: any) => {
  productInfo.value = Object.assign({}, item);
  buyShow.value = true;
};

//购买华为云服务器
const goBuyGov = (item: any) => {
  // router.push(`/client/cloudService/components/shoppingHome?type=buy&name=${item.name}`);
  if (!item.jumpUrl) {
    return;
  }
  window.open(
    item.jumpUrl.includes("http") ? item.jumpUrl : `https://${item.jumpUrl}`,
    "_blank"
  );
};

// 跳转政务云
const handleToGov = () => {
  router.push("/client/cloudGovernment");
};

// 跳转云市场
const handleToMarket = () => {
  router.push("/client/cloudMarketplace");
};

// 跳转云市场详情
const handleToMarketDetail = (item: any) => {
  router.push({
    path: "/client/cloudMarketplace/components/shopping",
    query: {
      marketId: item.marketId,
    },
  });
};
</script>
<style lang="less" scoped>
.service-msg-box {
  height: 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-right: 20px;
  margin: 10px 0;
  border-bottom: 1px solid #ccc;

  .detailed-information {
    font-weight: 700;
  }
}
.go-buy {
  height: 40px;
  border-radius: 20px;
}
.preferential-price {
  color: #f63f3f;
  margin-bottom: 30px;
}

.price-box {
  font-size: 20px;
  font-weight: 600;
  margin-top: 20px;
}
.add-MySQL {
  margin-bottom: 20px;
}
.form-item-box {
  border-bottom: 1px solid #ccc;
}
.tag-box {
  margin: 10px 0 30px 0;
  .tag-one {
    margin-right: 10px;
  }
}
.service-title {
  margin-bottom: 10px;
}
.icon-box {
  margin-left: 10px;
}
.category-row {
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 0 10px #c7c7c7;
  margin-bottom: 30px;
  overflow-x: auto;
  overflow-y: hidden;
  .category-item {
    line-height: 70px;
    flex: 1;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    background-color: #fff;
    transition: all 0.5s;
    border: 1px solid #ccc;
    cursor: pointer;
  }
  .actvie {
    color: #fff;
    background-color: #3f6bf6;
  }
  &::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  scrollbar-width: none;
  -ms-overflow-style: none;
  &::-webkit-scrollbar-track {
    background: transparent;
    border-width: 0;
    overflow: hidden;
  }
  &::-webkit-scrollbar-thumb {
    background: #3f6bf6;
    border-radius: 10px;
    border-width: 0;
    width: 6px;
  }
}
.list {
  margin-bottom: 30px;
  .left-sapn {
    padding: 30px;
    min-height: 590px;
    // background: linear-gradient(to bottom, #65d7f8, #469be8);
    background: url("@/assets/img/client/home/cloud1.jpg");
    background-size: 100% 100%;
    background-repeat: no-repeat;
    cursor: pointer;
    .left-title {
      font-size: 22px;
      color: #fff;
      padding-bottom: 50px;
      border-bottom: 1px solid #fff;
    }
    .left-item {
      padding: 24px 0;
      line-height: 25px;
      color: #fff;
      font-size: 14px;
      display: flex;
      align-items: center;
      border-bottom: 1px solid #fff;
      span {
        margin-left: 20px;
      }
    }
    .left-content {
      padding: 24px 0;
      line-height: 25px;
      color: #fff;
      font-size: 14px;
    }
    .left-advantage {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;

      > div {
        width: 45%;
        color: #fff;
        background-color: rgba(255, 255, 255, 0.2);
        text-align: center;
        height: 30px;
        line-height: 30px;
        margin-bottom: 20px;
        span::before {
          content: "√";
          font-weight: 600;
          margin-right: 10px;
        }
      }
    }
    .learnMore {
      width: 140px;
      height: 40px;
      line-height: 40px;
      text-align: center;
      margin-top: 30px;
      color: #fff;
      transition: all 0.3s;
      border: 1px solid #fff;
      &:hover {
        cursor: pointer;
        border: 1px solid #9ac2f0;
        background-color: #4098ff;
      }
    }
  }
  .purple {
    background: url("@/assets/img/client/home/cloud2.jpg");
    background-size: 100% 100%;
    background-repeat: no-repeat;
  }
  .list-row {
    height: 100%;
    display: flex;
    flex-wrap: wrap;
    .item {
      width: 50%;
      display: flex;
      flex-direction: column;
      padding: 30px 40px !important;
      background-color: #fff;
      border-bottom: 1px solid #e4e4e4;
      border-right: 1px solid #e4e4e4;
      transition: all 0.5s;
      position: relative;
      &:hover {
        box-shadow: 0 0 20px #c5c5c5;
        z-index: 2;
        .btn {
          display: block;
        }
        .name {
          color: #3369ff;
        }
      }
      &:nth-child(2n) {
        border-right: none;
      }
      &:nth-last-of-type(2),
      &:nth-last-of-type(1) {
        border-bottom: none;
      }
      .name {
        color: #212a40;
        margin-bottom: 10px;
        transition: all 0.5s;
        font-size: 16px;
        line-height: 24px;
        font-weight: 600;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        word-break: break-all;
      }

      .into {
        color: #6d7383;
        font-size: 14px;
        margin-bottom: 10px;
        min-height: 20px;
        line-height: 20px;
        overflow: hidden;
        display: -webkit-box;
        text-overflow: ellipsis;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
      }

      .btn-content {
        color: #909090;
        font-size: 14px;
        margin-bottom: 20px;

        .btn-name {
          display: inline-block;
          padding: 4px 10px;
          border: 1px solid #c4c4c4;
        }
      }

      .price {
        color: #e86240;
        font-weight: 600;
        font-size: 20px;
        span {
          font-size: 80%;
        }
      }
      .btn {
        display: none;
        width: 140px;
        background-color: #3f6bf6;
        color: #fff;
        padding: 10px;
        text-align: center;
        position: absolute;
        transition: all 0.5s;
        bottom: 20px;
        right: 20px;
        &:hover {
          cursor: pointer;
        }
      }
    }

    .item-huaweiyun {
      min-height: 590px;
    }
  }
}

.content-title {
  margin-top: 100px;
}
.content-container {
  margin-top: 50px;
}
</style>
